package com.wms.controller;

import com.wms.dto.ItemDateDto;
import com.wms.dto.ItemUpdateDto;
import com.wms.pojo.PageResult;
import com.wms.pojo.Result;
import com.wms.service.ItemService;
import com.wms.vo.ItemEchoVo;
import com.wms.vo.ItemSkuSpuListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author Yzxxn
 */
@RestController
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("/sku/page")
    private Result getSkuByPage(String title,String code,Integer pageNum,Integer pageSize){
        PageResult result=itemService.getSkuByPage(title,code,pageNum,pageSize);
        return Result.success(result);
    }

    @GetMapping
    public Result page(Integer page,Integer pageSize,String code,String title,String category){
        PageResult pageResult = itemService.page(page,pageSize,code,title,category);
        return Result.success(pageResult);
    }

    //添加商品消息
    @PostMapping
    public Result addItem(@RequestBody ItemDateDto dto){
        itemService.addItem(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getItemDateById(@PathVariable Integer id){
        ItemEchoVo vo = itemService.getItemDateById(id);
        return Result.success(vo);
    }

    //修改
    @PutMapping
    public Result updateItemDate(@RequestBody ItemUpdateDto dto){
        itemService.updateItemDate(dto);
        return Result.success();
    }


    //查询所有
    @GetMapping("/all")
    public Result getItemsAllList(Integer pageSelect,Integer pageSizeSelect,String skuName,String spuCode){
        ItemSkuSpuListVo vo = itemService.getItemsAllList(pageSelect,pageSizeSelect,skuName,spuCode);
        return Result.success(vo);
    }
}
